package com.jtcoding.chat.controller;

import com.jtcoding.chat.model.FriendRequest;
import com.jtcoding.chat.model.Result;
import com.jtcoding.chat.model.User;
import com.jtcoding.chat.service.FriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jason.tang
 * @create 2019-01-02 15:11
 * @description
 */
@Api(tags = "好友相关")
@RestController
@RequestMapping("/friends")
public class FriendController {

    @Autowired
    private FriendService friendService;

    @ApiOperation(value = "获取好友列表", notes = "获取用户的好友列表")
    @GetMapping("/{userNum}")
    public Result<List<User>> getFriendListByUserNum(@PathVariable Integer userNum) {
        return Result.success(friendService.getFriendListByUserNum(userNum));
    }

    @ApiOperation(value = "搜索好友", notes = "搜索好友")
    @GetMapping("/search/{keyword}")
    public Result<List<User>> searchUser(@PathVariable String keyword) {
        return Result.success(friendService.searchUser(keyword));
    }

    @ApiOperation(value = "添加好友", notes = "添加好友")
    @PostMapping("/requests")
    public Result<Boolean> addFriendRequest(@RequestBody FriendRequest friendRequest) {
        return Result.success(friendService.addFriendRequest(friendRequest));
    }

    @ApiOperation(value = "显示好友申请列表", notes = "显示好友申请列表")
    @GetMapping("/requests/{userNum}")
    public Result<List<User>> getUserByFriendReq(@PathVariable Integer userNum) {
        return Result.success(friendService.getUserByFriendReq(userNum));
    }

    @ApiOperation(value = "接受好友申请", notes = "接受好友申请")
    @PutMapping("/requests/accept")
    public Result<User> acceptFriendRequest(@RequestBody FriendRequest friendRequest) {
        return Result.success(friendService.acceptFriendRequest(friendRequest));
    }

    @ApiOperation(value = "拒绝好友申请", notes = "拒绝好友申请")
    @PutMapping("/requests/reject")
    public Result<Boolean> rejectFriendRequest(@RequestBody FriendRequest friendRequest) {
        return Result.success(friendService.rejectFriendRequest(friendRequest));
    }

}